package com.fengye.common.constants;

import com.fengye.common.utils.I18nUtil;

/**
 * @author sunlei
 * @description 应用错误码枚举
 */
public enum AppHttpCodeEnum implements IBaseHttpCodeEnum {

    /********** 一、常用服务器错误码 ***********/
    SUCCESS(true, 200, I18nUtil.message("request.success")),
    FAIL(false,400, I18nUtil.message("request.fail")),
    NOT_FOUND(false,404, I18nUtil.message("request.notFound")),
    METHOD_NOT_ALLOWED(false,405, I18nUtil.message("request.methodNotSupport")),
    UNSUPPORTED_MEDIA_TYPE(false,415, I18nUtil.message("request.unsupportedMediaType")),
    SYSTEM_ERROR(false,500, I18nUtil.message("request.systemError")),

    /********** 二、自定义业务枚举，【前两位表示业务模块，后三位表示具体的业务或服务器通用代码】*********/

    // 20：认证、授权相关
    USER_NOT_FOUND(false, 20001, I18nUtil.message("user.notExist")),
    USER_PWD_ERROR(false, 20002, I18nUtil.message("user.pwd.error")),
    USERNAME_OR_PWD_ERROR(false, 20003, I18nUtil.message("user.usernamePwd.error")),
    UNAUTHORIZED(false,20401, I18nUtil.message("user.unauthorized")),
    FORBIDDEN(false,20403, I18nUtil.message("user.forbidden")),
    TOKEN_INVALID(false, 21007, I18nUtil.message("user.token.invalid")),
    TOKEN_EXPIRED(false, 21008, I18nUtil.message("user.token.expired")),
    TOKEN_RESET(false, 21009, I18nUtil.message("user.token.reset")),

    // 21：用户模块
    USER_REG_ERROR(false, 21001, I18nUtil.message("user.register.fail")),
    USER_IS_DELETED(false, 21002, I18nUtil.message("user.isDeleted")),
    USER_ALREADY_EXIST(false, 21003, I18nUtil.message("user.username.existed")),
    MODIFIED_AVATAR_ERROR(false, 21004, I18nUtil.message("user.modify.avatar.fail")),
    MODIFY_USERINFO_ERROR(false, 21005, I18nUtil.message("user.modify.info.fail")),
    MODIFY_PWD_ERROR(false, 21006, I18nUtil.message("user.modify.pwd.fail")),

    // 30：重签模块
    RESIGN_IPA_ERROR(false, 30001, I18nUtil.message("resign.ipa.fail")),

    // 70：系统限流
    TOO_MANY_REQUESTS(false, 70001, I18nUtil.message("limit.server.tooManyRequests")),
    TOO_MANY_SAMPLE_REQUESTS(false, 70002, I18nUtil.message("limit.sample.tooManyRequests")),

    // 80：参数校验，一般不要用
    PARAM_ERROR(false, 80001, "request.param.error"),

    // 未知异常
    UNKNOWN_ERROR(false,99999, I18nUtil.message("request.unknownError"));


    private final Boolean success;
    private final Integer code;
    private final String msg;

    // constructor
    AppHttpCodeEnum(Boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.msg = message;
    }

    // getter
    @Override
    public Boolean getSuccess() {
        return success;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }
}
